﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BadassPhotoAlbum
{
    class OLDBADCODE
    {
    }
}
/*using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BadassPhotoAlbum
{
    /// <summary>
    /// This form is used to display and get information about a picture when it is being added
    /// 
    /// Version 1 
    /// Created by Ryan Hall 9-27-11
    /// </summary>
    public partial class AddPictureForm : Form
    {
        private string defaultName;
        private string pictureName;
        private PictureStruct picture;
        private bool incorrectFile;

        public string PictureName
        {
            get { return pictureName; }
        }
        public PictureStruct Picture
        {
            get { return picture; }
        }
        public bool IncorrectFile
        {
            get { return incorrectFile; }
        }


        /// <summary>
        /// Basic constructor for the form
        /// sets albumLabel text and the working photo
        /// 
        /// Version 1.1
        /// Bug Fix 10-7-11 - Ethan Boyer
        /// Version 1 
        /// Created by Ryan Hall 9-27-11
        /// </summary>
        /// <param name="photo">the photo to add</param>
        /// <param name="album">the album that it is added to</param>
        public AddPictureForm(PictureStruct picture, string defaultName)
        {
            InitializeComponent();
            try
            {
                showPictureBox.Image = Image.FromFile(picture.OriginalPath);
            }
            catch
            {
                MessageBox.Show("Can't open the picture", "Error", MessageBoxButtons.OK);
                incorrectFile = true;
                this.Close();
            }

            this.nameTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.KeyDownEventHandler); // key down event

            this.defaultName = defaultName;
            this.picture = picture;
            pictureName = null;
            
        }

        /// <summary>
        /// Gets the information form the form, puts in the photo and leaves the form
        /// 
        /// Version 1 
        /// Created by Ethan Boyer 9-27-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addButton_Click(object sender, EventArgs e)
        {
            // no name
            if (nameTextBox.Text.Length < 1)
            {
                //DialogResult result =  MessageBox.Show("No name entered, would you like the default name: " + album.Name + album.NumberOfDefaultNames, "No name", MessageBoxButtons.YesNo);
                DialogResult result = MessageBox.Show("No name entered, would you like the default name: " + defaultName, "No name", MessageBoxButtons.YesNo);
                if (result == DialogResult.No) // wants to change the name
                {
                    return;
                }
                //photo.Relationship.PictureName = album.Name + album.NumberOfDefaultNames.ToString(); // set the default name
                //album.NumberOfDefaultNames++;
                pictureName = defaultName;
                this.Close();
                return;
            }

            // has a name, check for invalid characters
            if(!ProgramDb.CheckInput(nameTextBox.Text))
            {
                nameTextBox.Focus();
                nameTextBox.SelectAll();
                return; // fault in text
            }

            pictureName = nameTextBox.Text; // set the property that is read from outside the form

            this.Close(); // closes when calling method closes
        }

        /// <summary>
        /// User cancels adding the picture
        /// 
        /// Version 1 
        /// Created by Ethan Boyer 9-27-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cancelButton_Click(object sender, EventArgs e)
        {
            pictureName = null;
            this.Close();
        }

        /// <summary>
        /// handle keypresses when addpicture form is focused
        /// copied from newalbumform
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-26-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void KeyDownEventHandler(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Enter: addButton_Click(sender, e);
                    break;
                case Keys.Escape: cancelButton_Click(sender, e);
                    break;
            }
        }
    }
}
*/
/*using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BadassPhotoAlbum
{
    /// <summary>
    /// A form to view a list of albums
    /// 
    /// Version 1.1 Ryan Hall 9-25-11
    /// launches AlbumFormView when album is opened
    /// added a window menu item and click event
    /// Version 1
    /// Created by Ryan Hall 9-22-11
    /// </summary>
    public partial class AlbumSelectionForm : Form
    {
        private ProgramDb rProgramDb; // the database to access
        private List<AlbumStruct> albums; // a list of albums from a search of the database
        private ToolStripMenuItem windowMenuItem; // item in the window menu

        //event to be raised on click of Create New Album Button
        public event EventHandler<CreateAlbumClickEvent> RaiseCustomEvent;
        public event EventHandler<OpenAlbumEvent> RaiseOpenEventHandler; // event for opening the selected album


        /// <summary>
        /// basic constructor for the form
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-22-11
        /// </summary>
        /// <param name="database">used to access the database</param>
        public AlbumSelectionForm(ProgramDb database, ToolStripMenuItem windowMenu)
        {
            InitializeComponent();

            rProgramDb = database;

            // handler for double click
            albumListView.DoubleClick += albumListView_DoubleClick;

            // subscribe the albumListView to the keyboard event 
            this.albumListView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.KeyDownEventHandler);
            this.Disposed += DisposedEvent; // corner x close button

            // add the window menu item
            windowMenuItem = new ToolStripMenuItem(this.Text, null, new EventHandler(windowMenuItem_Click));
            windowMenu.DropDownItems.Add(windowMenuItem);
        }

        /// <summary>
        /// Called when the form closes, called by the X button
        /// Cleans up the window menu
        /// 
        /// Version 1
        /// Created By Ryan Hall 9-27-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DisposedEvent(object sender, EventArgs e)
        {
            windowMenuItem.Dispose();
        }

        /// <summary>
        /// Brings the window into focus and a normal state when the menu strip item is clicked
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-27-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void windowMenuItem_Click(object sender, EventArgs e)
        {
            this.Focus();
            this.WindowState = FormWindowState.Normal;
        }

        /// <summary>
        /// Loads into the form all basic information
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-22-11
        /// </summary>
        /// <param name="sender">System info</param>
        /// <param name="e">system info</param>
        private void AlbumSelectionForm_Load(object sender, EventArgs e)
        {
            // get a list of albums from the database
            albums = rProgramDb.GetAllAlbums();

            albumListView.FullRowSelect = true;

            // clear the list
            albumListView.Items.Clear();
            // needs improvement
            //albumListView.Sorting = SortOrder.Ascending;
            
            foreach (var album in albums)
            {
                ListViewItem item = new ListViewItem(album.Name, 0); // create an item that is a row in listview
                item.SubItems.Add(album.TimeOfCreation.ToString()); // create a subitem, information for a column
                item.SubItems.Add(album.PrimaryKey.ToString());
                albumListView.Items.AddRange(new ListViewItem[] { item });
            }
        }

        /// <summary>
        /// handle keypresses when albumListView is focused
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-26-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void KeyDownEventHandler(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Enter:
                    if (albumListView.SelectedIndices.Count > 0)
                    {
                        openButton_Click(sender, e);
                    }
                    break;
                case Keys.Delete:
                    if (albumListView.SelectedIndices.Count > 0)
                    {
                        deleteAlbumButton_Click(sender, e);
                    }
                    break;
            }
        }

        /// <summary>
        /// opens the selected album
        /// 
        /// Version 1.1 by Ryan Hall 9-25-11
        /// now fires the open album event
        /// Version 1
        /// Created by Ryan Hall 9-23-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void openButton_Click(object sender, EventArgs e)
        {
            // return if nothing selected
            if (albumListView.SelectedIndices.Count == 0)
            {
                return;
            }
            
            // debugging purposes
            //MessageBox.Show("Thats right bitches " + albumListView.SelectedIndices[0], "Ryan is the greatest", MessageBoxButtons.OK);

            // get the albumId
            AlbumStruct album = albums[albumListView.SelectedIndices[0]];
            
            // debugging help
            //MessageBox.Show("Thats right bitches " + album.PrimaryKey, "Ryan is the greatest", MessageBoxButtons.OK);

            // event to fire
            RaiseOpenEvent(new OpenAlbumEvent(album));
            this.Close();
        }

        /// <summary>
        /// When the open event happens
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-25-11
        /// </summary>
        /// <param name="e"></param>
        private void RaiseOpenEvent(OpenAlbumEvent e)
        {
            // Make a temporary copy of the event to avoid possibility of
            // a race condition if the last subscriber unsubscribes
            // immediately after the null check and before the event is raised.
            EventHandler<OpenAlbumEvent> handler = RaiseOpenEventHandler;

            // Event will be null if there are no subscribers
            if (handler != null)
            {
                handler(this, e);
            }
        }
        
        /// <summary>
        /// handler for double click in albumListView
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-23-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void albumListView_DoubleClick(object sender, EventArgs e)
        {
            openButton_Click(sender, e);
        }

        /// <summary>
        /// Closes form
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-23-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// When the Create album event is fired
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-23-11
        /// </summary>
        /// <param name="e"></param>
        protected virtual void RaiseCreateAlbumClick(CreateAlbumClickEvent e)
        {
            // Make a temporary copy of the event to avoid possibility of
            // a race condition if the last subscriber unsubscribes
            // immediately after the null check and before the event is raised.
            EventHandler<CreateAlbumClickEvent> handler = RaiseCustomEvent;

            // Event will be null if there are no subscribers
            if (handler != null)
            {
                handler(this, e);
            }
            
        }

        /// <summary>
        /// Creates a new album, fires CreateAlbumClickEvent to lauch the NewAlbumForm in main
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-23-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void createAlbumButton_Click_1(object sender, EventArgs e)
        {
            // fire the event
            RaiseCreateAlbumClick(new CreateAlbumClickEvent());

            // destroy the window menu item
            windowMenuItem.Dispose();
            
            // can be first, who would've thought?
            this.Close();
        }

        /// <summary>
        /// Delete the selected album from the database
        /// now properly deletes the relationships of the album
        /// 
        /// Version 2 by Ryan Hall 9-26-11
        /// properly deletes relationships now, whoops
        /// Version 1
        /// Created by Ethan Boyer 9-24-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteAlbumButton_Click(object sender, EventArgs e)
        {
            // nothing selected
            if (albumListView.SelectedIndices.Count == 0)
            {
                return;
            }

            //confirm delete
            DialogResult confirm = MessageBox.Show("Are you sure you want to delete the selected album: " + albums[albumListView.SelectedIndices[0]].Name, "Confirm", MessageBoxButtons.YesNo);
            if (confirm == DialogResult.No)
            {
                return;
            }

            // get the selected albumID
            UInt32 albumId = albums[albumListView.SelectedIndices[0]].PrimaryKey;

            //Properly dispose of the relationships in the deleted album
            List<RelationshipStruct> relationshipsToDelete;
            relationshipsToDelete = rProgramDb.GetRelationships(albumId); // get a list of the relationships
            foreach (var r in relationshipsToDelete)
            {
                rProgramDb.deleteRelationship(r.PrimaryKey); // make them go away
            }
            rProgramDb.SaveRelationshipDb();

            // debugging help
            //MessageBox.Show("Thats right bitches " + albumId, "Ryan is the greatest", MessageBoxButtons.OK);

            rProgramDb.DeleteAlbum(albumId);
            rProgramDb.SaveAlbumDb();

            // reload the list
            AlbumSelectionForm_Load(sender, e);
        }
    }
}*/
/*using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BadassPhotoAlbum
{
    /// <summary>
    /// This form is opened when an album is to be viewed.
    /// It interacts with the album class to add, delete, modify and view pictures in an album
    /// 
    /// Version 1
    /// Created by  9-27-11 Ethan Boyer
    /// </summary>
    public partial class AlbumViewForm : Form
    {
        // constants
        private const int THUMBNAILSIZE = 200; // the max size, width and height of thumbnails
        private ToolStripMenuItem windowMenuItem; // item in the window menu
        private Album album; // the open album
        private PictureBox viewPhoto; // the picture to be displayed in the picture tab, used to destroy the picture if it is deleted
        private int viewedPhoto; // the index of the photo that is curretly being viewed by viewPhoto
        private int selectedIndex; // used so that the user can still modify picture details while in viewPhotoTab
        private bool dirty; // wheter to ask for a save on exit
        
        //events
        public event EventHandler<CloseAlbumViewEvent> RaiseCloseEventHandler;
        public event EventHandler<BackToSelectionEvent> RaiseBackToSelectionEventHandler;

        // allow read access to the album
        public Album FormAlbum
        {
            get { return album; }
        }

        /// <summary>
        /// The constructor for the form
        /// 
        /// Version 1
        /// Created by Ethan Boyer 9-27-11
        /// </summary>
        /// <param name="programDb">the database</param>
        /// <param name="album">name of the album being worked on</param>
        /// <param name="windowMenu">menu to place the window menuitem into</param>
        public AlbumViewForm(ProgramDb programDb, AlbumStruct album, ToolStripMenuItem windowMenu)
        {
            InitializeComponent();

            this.Text = album.Name; // set the text that appears at the top of the form
            this.FormClosing += OnClosing; // when the x button is pressed trying to close the form, or the main program x button is pressed
            detailsListView.SelectedIndexChanged += DisplayDetails; // when the selected index of the list box is changed
            pictureFlowLayoutPanelTab3.SizeChanged += SizePhoto; // resize the picture to the container
            detailsListView.DoubleClick += viewButton_Click; // double click an item in the list
            detailsListView.KeyDown += DetailsKeyEvents; // key events for the object
            photoNameTextBox.KeyDown += ModifyKeyEvents; // key events for the object

            this.album = new Album(programDb, album);
            dirty = false;

            // add the window menu item using the Text property of the form, Text is what is displayed at the top of the form
            windowMenuItem = new ToolStripMenuItem(this.Text, null, new EventHandler(windowMenuItem_Click)); // and add the link to the method that the event call
            windowMenu.DropDownItems.Add(windowMenuItem); // add the item to the menustrip
        }

        /// <summary>
        /// Handles button press for detailsListView
        /// 
        /// Version 1
        /// Created by Ryan Hall 10-9-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DetailsKeyEvents(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Enter:
                    viewButton_Click(sender, e);
                    break;
                case Keys.Delete:
                    deleteButton_Click(sender, e);
                    break;
            }
        }

        /// <summary>
        /// Handles button press for modifing Pictures
        /// 
        /// Version 1
        /// Created by Ryan Hall 10-9-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ModifyKeyEvents(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Enter:
                    modifyButton_Click(sender, e);
                    break;
            }
        }

        /// <summary>
        /// Brings the window into focus and a normal state when the menu strip item is clicked
        /// 
        /// Version 1
        /// Created by Ethan Boyer 9-27-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void windowMenuItem_Click(object sender, EventArgs e)
        {
            this.Focus();
            this.WindowState = FormWindowState.Normal;
        }
        
        /// <summary>
        /// Called When the form is first Initialized and when photos are added/removed.
        /// This method only updates the Program User's View. It does NOT Save Changes to the DataBase.
        /// 
        /// Version 1.2 Modified By Ryan Hall 9-27-11
        /// changed names of class variables
        /// Version 1.1
        /// Modified By Ethan Boyer 9-26-11
        /// Version 1
        /// Created By Ryan Hall 9-25-11
        /// </summary>
        private void PopulateDetailsListView()
        {
            // clear out the list
            detailsListView.Items.Clear();

            // load the info into the list
            foreach (PhotoStruct p in album.Photos)
            {
                ListViewItem item = new ListViewItem(p.Relationship.PictureName, 0);// create an item that is a row in listview
                item.SubItems.Add(p.Relationship.TimeOfCreation.ToString());// create a subitem, information for a column
                detailsListView.Items.AddRange(new ListViewItem[] {item});
            }
        }

        /// <summary>
        /// Called when the form loads,
        /// populates theListOfRelationships and theListOfPictures
        /// then puts info in DetailsListView
        /// Basic functionality so Ethan can finish 
        ///
        /// Version 1.1 Modified by Ryan Hall 9-27-11
        /// Rewritten to account for new names, types and variables
        /// Version 1
        /// Created by Ryan Hall 9-25-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AlbumViewForm_Load(object sender, EventArgs e)
        {
            PopulateDetailsListView(); // show the list          
            LoadThumbnailsPanel(); // add the pictures to the thumbnailsFlowLayoutPanel
            selectedIndex = -1; // the false state
        }

        /// <summary>
        /// Add the thumbnails to tab 2, for all photosList that are saved
        /// 
        /// Version 1.1 Modified by Ryan Hall 9-28-11
        /// Rewritten to account for new names, types and variables
        /// Version 1
        /// Created by Ryan Hall 9-25-11
        /// </summary>
        private void LoadThumbnailsPanel()
        {
            thumbnailsFlowLayoutPanel.Controls.Clear();

            foreach (var p in album.Photos)
            {
                try
                {
                    p.image = new PictureBox();
                    if(p.state == PhotoStruct.State.added) // wether the picture is in the database or not
                    {
                        p.image.Image = GetThumbnail(p.Picture.OriginalPath);
                    }
                    else // shouldn't be called as the method is only called on form load
                    {
                        p.image.Image = GetThumbnail(p.Picture.Path);

                    }
                    // load the picture from its saved path, new pics will load form old path
                    p.image.SizeMode = PictureBoxSizeMode.Zoom;
                    p.image.Size = new Size(THUMBNAILSIZE, THUMBNAILSIZE);
                    p.image.Parent = thumbnailsFlowLayoutPanel;
                }
                catch
                {
                    // skip it for now
                }
            }
        }

        /// <summary>
        /// When the open event happens
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-25-11
        /// </summary>
        /// <param name="e"></param>
        private void RaiseCloseEvent(CloseAlbumViewEvent e)
        {
            // Make a temporary copy of the event to avoid possibility of
            // a race condition if the last subscriber unsubscribes
            // immediately after the null check and before the event is raised.
            EventHandler<CloseAlbumViewEvent> handler = RaiseCloseEventHandler;

            // Event will be null if there are no subscribers
            if (handler != null)
            {
                handler(this, e);
            }
        }

        /// <summary>
        /// Opens the Album selection form again
        /// Does not close album
        /// 
        /// Version 1
        /// Created by Ethan Boyer 9-26-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backAlbumViewButton_Click(object sender, EventArgs e)
        {
            RaiseBackToAlbumeEvent(new BackToSelectionEvent());
        }

        /// <summary>
        /// Fires the event to open the album selection form
        /// 
        /// Version 1
        /// Created by Ethan Boyer 9-26-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RaiseBackToAlbumeEvent(BackToSelectionEvent e)
        {
            //Raise the event
            EventHandler<BackToSelectionEvent> handler = RaiseBackToSelectionEventHandler;

            // Event will be null if there are no subscribers
            if (handler != null)
            {
                handler(this, e);
            }
        }

        /// <summary>
        /// Adds a picture to the album
        /// Does not save in the database, that is done when the save button is clicked
        /// 
        /// Version 1.1
        /// Fixed "adding .jpg" bug 10-7-11 - Ethan Boyer
        /// Version 1
        /// Created by Ethan Boyer 9-27-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addButton_Click(object sender, EventArgs e)
        {
            // open a dialog to get the photo
            OpenFileDialog open = new OpenFileDialog();
            // set the dialog box filter
            open.Filter = "picture files (*.jpg, *.jpeg *.bmp, *.gif, *.png)| *.jpg; *.jpeg; *.bmp; *.gif; *.png";
            open.ShowDialog();
            if (open.FileName.Length == 0) // if nothing was selected
            {
                return;
            }

            // a struct to hold the temp picture
            PictureStruct pic = new PictureStruct();
            pic.OriginalPath = open.FileName;
            pic.TimeOfCreation = DateTime.Now;

            // open the add picture form, send in the default name from the album
            AddPictureForm addPictureForm = new AddPictureForm(pic, album.GetDefaultName());
            if (addPictureForm.IncorrectFile)
            {
                return;
            }

            addPictureForm.ShowDialog();

            // check if the user canceled adding the picture
            if(addPictureForm.PictureName == null)
            {
                return;
            }

            // add to the album and get the photo so that a thumbnail can be added to the thumbnails tab
            PhotoStruct photo = album.AddPhoto(pic, addPictureForm.PictureName);
            try
            {
                photo.image = new PictureBox();
                photo.image.Image = GetThumbnail(photo.Picture.OriginalPath);
                photo.image.SizeMode = PictureBoxSizeMode.Zoom;
                photo.image.Size = new Size(THUMBNAILSIZE, THUMBNAILSIZE);
                photo.image.Parent = thumbnailsFlowLayoutPanel;
            }
            catch
            {
                return;
            }

            // update the form list
            PopulateDetailsListView();
            Dirty(); // set the dirty state
        }

        /// <summary>
        /// when the close button is clicked
        /// 
        /// Version 1
        /// Created by Ethan Boyer 9-25-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void closeButton_Click_1(object sender, EventArgs e)
        {
            //call the overriden form closing event
            OnClosing(sender, new FormClosingEventArgs(CloseReason.MdiFormClosing, false));
        }

        /// <summary>
        /// This method is called when 'Delete Photo' Button is clicked
        /// 
        /// Version 1.2 by Ryan Hall 9-27-11
        /// rewrtten to make the different form functionallity
        /// Version 1.1 by Ryan Hall 9-27-11
        /// commented out rProgramDb.deletePicture(pictureID) as the picture may be used by another album theListOfPictures may need to be reworked so the dataview panel is currently wrong as
        /// Version 1
        /// Created by Ethan Boyer 9-26-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>   
        private void deleteButton_Click(object sender, EventArgs e)
        {
            //checks if anything is selected
            if (detailsListView.SelectedIndices.Count == 0)
            {
                return;
            }

            // confirm delete
            DialogResult result = MessageBox.Show("Are you sure you would like to delete " + album.Photos[detailsListView.SelectedIndices[0]].Relationship.PictureName, "Confirm Delete", MessageBoxButtons.YesNo);
            if (result == DialogResult.No)
            {
                return;
            }

            // delete viewPhoto if it is the one being deleted
            if (viewedPhoto == detailsListView.SelectedIndices[0])
            {
                viewPhoto.Image = null;
                selectedIndex = -1;
                photoNameTextBox.Text = "";
                pictureFlowLayoutPanelTab3.Size = new Size(0, 0);
            }

            //gets the selected photo and change form name if necessary
            album.DeletePhoto(detailsListView.SelectedIndices[0]);// pass the index of the photo to delete
            Dirty(); // set the dirty state
            PopulateDetailsListView(); //updates the information in the DataView Panel

            // set selectedIndex to -1 to prevent errors
            selectedIndex = -1;
        }

        /// <summary>
        /// Add an asterix to the text property of the form to indicate that it has been changed and needs to be saved
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-29-11
        /// </summary>
        /// <param name="dirty">Set the asterix if true</param>
        private void Dirty()
        {
            if (dirty == false)
            {
                this.Text += "*";
                this.dirty = true; // set the state of the dirty flag for the form
            }    
        }

        /// <summary>
        /// Saves the album
        /// 
        /// Version 1
        /// Created by Ethan Boyer 9-28-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveButton_Click(object sender, EventArgs e)
        {
            // reset the form text
            album.SaveAlbum();
            this.Text = album.Properties.Name;
            dirty = false; // reset the flag
        }

        /// <summary>
        /// Puts the seleced picture onto tab 3 for viewing and changes the selected tab
        /// 
        /// Version 1
        /// Created by Ethan Boyer 9-29-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void viewButton_Click(object sender, EventArgs e)
        {
            // return if nothing selected
            if (detailsListView.SelectedIndices.Count == 0)
            {
                return;
            }

            // clear out the previous photo
            if (viewPhoto != null)
            {
                viewPhoto.Dispose();
            }

            // set the viewedPhoto marker
            viewedPhoto = detailsListView.SelectedIndices[0];

            // create a new photo
            viewPhoto = new PictureBox();
            viewPhoto.SizeMode = PictureBoxSizeMode.Zoom;
            // if it is an added picture or a saved picture
            try
            {
                if (album.Photos[detailsListView.SelectedIndices[0]].state == PhotoStruct.State.added)
                {
                    viewPhoto.Image = Image.FromFile(album.Photos[detailsListView.SelectedIndices[0]].Picture.OriginalPath);
                }
                else if (album.Photos[detailsListView.SelectedIndices[0]].state == PhotoStruct.State.saved) // saved
                {
                    viewPhoto.Image = Image.FromFile(album.Photos[detailsListView.SelectedIndices[0]].Picture.Path);
                }
                else // modified
                {
                    if (album.Photos[detailsListView.SelectedIndices[0]].Picture.Path == null) // the picture was added but not yet saved
                    {
                        viewPhoto.Image = Image.FromFile(album.Photos[detailsListView.SelectedIndices[0]].Picture.OriginalPath);
                    }
                    else
                    {
                        viewPhoto.Image = Image.FromFile(album.Photos[detailsListView.SelectedIndices[0]].Picture.Path);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "View picture error", MessageBoxButtons.OK);
                return;
            }
                
            selectedIndex = detailsListView.SelectedIndices[0]; // set this so modify can work in viewPhoto tab
            SizePhoto(sender, e);
            viewPhoto.Parent = pictureFlowLayoutPanelTab3;
            // switch to the tab
            tabControl1.SelectedIndex = 2; // 2 is pictureTab2
        }

        /// <summary>
        /// Sizes the picture to fill the window
        /// 
        /// Version 1
        /// Created by Ethan Boyer 9-29-11
        /// </summary>
        private void SizePhoto(object sender, EventArgs e)
        {
            // no picture
            if (viewPhoto == null)
            {
                return;
            }
            // slightly reduce the picture size to keep scroll bars away
            int width = (int)((double)pictureFlowLayoutPanelTab3.Size.Width * .95);
            int height = (int)((double)pictureFlowLayoutPanelTab3.Size.Height * .95);

            viewPhoto.Size = new Size(width, height);

            /*
            //if (viewPhoto != null)
            //{
               // viewPhoto.Size = new Size(pictureFlowLayoutPanelTab3.Size.Width, pictureFlowLayoutPanelTab3.Size.Height);
            //}
             
        }

        /// <summary>
        /// override of inherited method
        /// Called when the form closes to ask the user if he wants to save changes
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-29-11
        /// </summary>
        private void OnClosing(object sender, FormClosingEventArgs e)
        {
            // ask if the user wants to save
            if (dirty)
            {
                DialogResult result = MessageBox.Show("Would you like to save the changes?", "Save?", MessageBoxButtons.YesNoCancel);
                if (result == DialogResult.Yes)
                {
                    this.album.SaveAlbum();
                }
                else if (result == DialogResult.Cancel)
                {
                    bool d = this.Disposing;
                    e.Cancel = true;
                    return;
                }
                // no closes the form
            }

            // clean up
            windowMenuItem.Dispose(); // clean up the window menu
            // fires the event
            AlbumStruct album = this.album.Properties;
            RaiseCloseEvent(new CloseAlbumViewEvent(album));
            this.Dispose();
        } 

        /// <summary>
        /// From http://msdn.microsoft.com/en-us/library/system.drawing.image.getthumbnailimage%28v=VS.90%29.aspx
        /// Creates a thumbnail of the image to reduce memory
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-30-11
        /// </summary>
        /// <param name="filename">the picture to get a thumbnail from</param>
        /// <returns>the thumbnail image</returns>
        private Image GetThumbnail(string filename)
        {
            Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
            Bitmap myBitmap = new Bitmap(filename);

            // get ratio, width to height for thumbnail. Ryan's
            int width;
            int height;
            if (myBitmap.Size.Width > myBitmap.Size.Height)
            {
                float ratio = (float)THUMBNAILSIZE / (float)myBitmap.Size.Width;
                width = (int)(myBitmap.Size.Width * ratio);
                height = (int)(myBitmap.Size.Height * ratio);
            }
            else
            {
                float ratio = (float)THUMBNAILSIZE / (float)myBitmap.Size.Height;
                width = (int)(myBitmap.Size.Height * ratio);
                height = (int)(myBitmap.Size.Width * ratio);
            }
            // end Ryan's

            Image myThumbnail = myBitmap.GetThumbnailImage(width, height, myCallback, IntPtr.Zero);
            return myThumbnail;
        }

        /// <summary>
        /// From http://msdn.microsoft.com/en-us/library/system.drawing.image.getthumbnailimage%28v=VS.90%29.aspx
        /// needed for GetThumnail()
        /// </summary>
        /// <returns></returns>
        public bool ThumbnailCallback()
        {
            return false;
        }

        /// <summary>
        /// Used to show details of the selected picture
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-30-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DisplayDetails(object sender, EventArgs e)
        {
            // return if nothing selected
            if (detailsListView.SelectedIndices.Count == 0)
            {
                return;
            }
            selectedIndex = detailsListView.SelectedIndices[0];
            // populate the picture details
            photoNameTextBox.Text = album.Photos[selectedIndex].Relationship.PictureName;
        }

        /// <summary>
        /// Modifies the selected picture, uses information form modidyNameTextBox
        /// 
        /// Version 1
        /// Created by Ethan Boyer 9-30-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void modifyButton_Click(object sender, EventArgs e)
        {
            // return if nothing selected
            if (selectedIndex == -1)
            {
                return;
            }

            if(photoNameTextBox.Text.Length == 0)
            {
                photoNameTextBox.Focus();
                return;
            }
            // check that the input is clean of xml friendly characters
            if(!ProgramDb.CheckInput(photoNameTextBox.Text))
            {
                photoNameTextBox.Focus();
                photoNameTextBox.SelectAll();
                return;
            }

            // modify the picture
            album.ModifyPhoto(selectedIndex, photoNameTextBox.Text);
            PopulateDetailsListView();  // update the view
            Dirty(); // set the dirty flag if necessary
        }
    }
}
*/
/*using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BadassPhotoAlbum
{
    /// <summary>
    /// Form for the creation of a new album
    /// 
    /// Version 1
    /// Created by Ryan Hall 9-23-11
    /// </summary>
    public partial class NewAlbumForm : Form
    {

        private ProgramDb rProgramDb; // where everything is stored
        public event EventHandler<OpenAlbumEvent> RaiseOpenEventHandler; // opens the selected album

        private ToolStripMenuItem windowMenuItem; // holds the link to this window in the menu strip

        /// <summary>
        /// Load the basic data used in the form
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-22-11
        /// </summary>
        /// <param name="database">the database to be used</param>
        public NewAlbumForm(ProgramDb database, ToolStripMenuItem windowMenu)
        {
            InitializeComponent();

            rProgramDb = database;

            nameTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(KeyDownEventHandler); // keypress event
            this.Disposed += DisposedEvent;

            // add the window menu item using the Text property of the form, Text is what is displayed at the top of the form
            windowMenuItem = new ToolStripMenuItem(this.Text, null, new EventHandler(windowMenuItem_Click));// and add the link to the method that the event call
            windowMenu.DropDownItems.Add(windowMenuItem);// add the item to the menustrip
        }

        /// <summary>
        /// Called when the form closes, called by the X button
        /// Cleans up the window menu
        /// 
        /// Version 1
        /// Created By Ryan Hall 9-27-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DisposedEvent(object sender, EventArgs e)
        {
            windowMenuItem.Dispose();
        }

        /// <summary>
        /// Brings the window into focus and a normal state when the menu strip item is clicked
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-27-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void windowMenuItem_Click(object sender, EventArgs e)
        {
            this.Focus();
            this.WindowState = FormWindowState.Normal;
        }

        /// <summary>
        /// The Enter button activates the selected form
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-26-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void KeyDownEventHandler(object sender, KeyEventArgs e)
        {
            if (nameTextBox.Focused == true && e.KeyCode == Keys.Enter)
            {
                createAlbumButton_Click(sender, e);
            }
        }

        /// <summary>
        /// close form
        /// 
        /// Version 1
        /// Created by Ethan Boyer 9-22-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// Adds new album to the database
        /// Launches album view of selected form
        /// ensures album names are unique
        /// 
        /// Version 1.2 Ryan Hall 9-27-11 now checks for uniqueness of album name
        /// Version 1.1 Ryan Hall 9-25-11 now opens the created album
        /// Version 1
        /// Created by Ryan Hall 9-23-11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void createAlbumButton_Click(object sender, EventArgs e)
        {
            // change to give a default name
            if (nameTextBox.Text.Length == 0)
            {
                MessageBox.Show("You have not entered an album name.", "Album Name", MessageBoxButtons.OK);
                return;
            }

            // check for xml characters
            if(!ProgramDb.CheckInput(nameTextBox.Text))
            {
                nameTextBox.Focus();
                nameTextBox.SelectAll();
                return;
            }
            
            // search for the album name in the database, no duplicates allowed
            if (rProgramDb.SearchAlbumName(nameTextBox.Text).Name != null) // the name was found
            {
                MessageBox.Show("You already have an album with that name.", "Album Name Conflict", MessageBoxButtons.OK);
                return;
            }

            // create the album and return a reference
            AlbumStruct album = Album.NewAlbum(nameTextBox.Text, rProgramDb);
            // fire event to open album view of new album
            RaiseOpenEvent(new OpenAlbumEvent(album));

            windowMenuItem.Dispose(); // get rid of the window menu item
            this.Close();
        }

        /// <summary>
        /// When the open event happens
        /// 
        /// Version 1
        /// Created by Ryan Hall 9-25-11
        /// </summary>
        /// <param name="e"></param>
        private void RaiseOpenEvent(OpenAlbumEvent e)
        {
            // Make a temporary copy of the event to avoid possibility of
            // a race condition if the last subscriber unsubscribes
            // immediately after the null check and before the event is raised.
            EventHandler<OpenAlbumEvent> handler = RaiseOpenEventHandler;

            // Event will be null if there are no subscribers
            if (handler != null)
            {
                handler(this, e);
            }
        }
    }
}
*/
/*using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;

namespace BadassPhotoAlbum
{
  partial class AboutBox : Form
  {
      public AboutBox()
      {
          InitializeComponent();
          this.Text = String.Format("About {0} {0}", AssemblyTitle);
          this.labelProductName.Text = AssemblyProduct;
          this.labelVersion.Text = String.Format("Version {0} {0}", AssemblyVersion);
          this.labelCopyright.Text = AssemblyCopyright;
          this.labelCompanyName.Text = AssemblyCompany;
          this.textBoxDescription.Text = AssemblyDescription;
      }

      #region Assembly Attribute Accessors

      public string AssemblyTitle
      {
          get
          {
              object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
              if (attributes.Length > 0)
              {
                  AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
                  if (titleAttribute.Title != "")
                  {
                      return titleAttribute.Title;
                  }
              }
              return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
          }
      }

      public string AssemblyVersion
      {
          get
          {
              return Assembly.GetExecutingAssembly().GetName().Version.ToString();
          }
      }

      public string AssemblyDescription
      {
          get
          {
              object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
              if (attributes.Length == 0)
              {
                  return "";
              }
              return ((AssemblyDescriptionAttribute)attributes[0]).Description;
          }
      }

      public string AssemblyProduct
      {
          get
          {
              object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
              if (attributes.Length == 0)
              {
                  return "";
              }
              return ((AssemblyProductAttribute)attributes[0]).Product;
          }
      }

      public string AssemblyCopyright
      {
          get
          {
              object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
              if (attributes.Length == 0)
              {
                  return "";
              }
              return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
          }
      }

      public string AssemblyCompany
      {
          get
          {
              object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
              if (attributes.Length == 0)
              {
                  return "";
              }
              return ((AssemblyCompanyAttribute)attributes[0]).Company;
          }
      }
      #endregion
  }
}
*/
/*using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BadassPhotoAlbum
{
    /// <summary>
    /// Event for opening the selected album
    /// 
    /// Version 1
    /// Created by Ryan Hall 9-25-11
    /// </summary>
    public class OpenAlbumEvent : EventArgs
    {
        private AlbumStruct album;

        public OpenAlbumEvent(AlbumStruct album)
        {
            this.album = new AlbumStruct();
            this.album = album;
        }

        public AlbumStruct Album
        {
            get { return album; }
            set { album = value; }
        }
    }

    /// <summary>
    /// Event for clicking on create new album button
    /// 
    /// Version 1
    /// Created by Ryan Hall 9-23-11
    /// </summary>
    public class CreateAlbumClickEvent : EventArgs
    {
        public CreateAlbumClickEvent()
        {
            // does nothing yet
            // will pass user name or id in future version
        }
    }

    /// <summary>
    /// An event to caputure the closing of a window
    /// 
    /// Version 1
    /// Created by Ryan Hall 9-25-11
    /// </summary>
    public class CloseAlbumViewEvent : EventArgs
    {
        private AlbumStruct album;

        public CloseAlbumViewEvent(AlbumStruct album)
        {
            this.album = new AlbumStruct();
            this.album = album;
        }

        public AlbumStruct Album
        {
            get { return album; }
            set { album = value; }
        }
    }

    public class BackToSelectionEvent : EventArgs
    {
        public BackToSelectionEvent()
        {
            // nothing
        }
    }
}
*/